/**
 * Created by HP on 2017/8/14.
 * 查看笔记内容
 */
window.onload=function(){
    var mytitle=document.getElementById("title");
    var mydate=document.getElementById("date");
    var mytext=document.getElementById("text");
    var back_button=document.getElementById("back");
    var edit_button=document.getElementById("edit");

    function setCookie(cname,cvalue)
    {

        document.cookie = cname + "=" + cvalue + "; ";
    }
    function getCookie(cname)
    {
        var name = cname + "=";
        var ca = document.cookie.split(';');
        for(var i=0; i<ca.length; i++)
        {
            var c = ca[i].trim();
            if (c.indexOf(name)==0) return c.substring(name.length,c.length);
        }
        return "";
    }
    var note_id=getCookie("note_show");

    var request=new XMLHttpRequest();
    request.open("POST","i/note/note/getNote",true);
    request.setRequestHeader("Content-type","application/x-www-form-urlencoded");
    var message="noteId="+note_id;
    request.onreadystatechange=function(){
        if(request.readyState==4)
        {
            if(request.status==200)
            {
                var data=JSON.parse(request.responseText);
                if(data.result==1)
                {
                    alert("请求成功");
                    mytitle.innerHTML=data.title;
                    mydate.innerHTML=data.updateTime;
                    mytext.innerHTMl=data.text;
                }
            }
            else{
                alert("请求错误"+request.status);
            }
        }
    }
    request.send(message);

    back_button.onclick=function(){
        window.location.href="mynotes.html";
    }
    edit_button.onclick=function(){
        setCookie("note",note_id);
        window.location.href="editLast.html";
    }
}